<template>
  <div class="app-container">
    <!-- Header 区域 -->
    <es-header></es-header>

    <!-- 商品 Item 项组件 -->
    <es-goods v-for="item in cartlist" :key="item.id"
      :id="item.id"
      :title="item.goods_name"
      :thumb="item.goods_img"
      :price="item.goods_price"
      :count="item.goods_count"
      :state="item.goods_state"
      @stateChange="getState"
      @countChange="getCount"
    ></es-goods>

    <!-- Foote 区域 -->
    <es-footer></es-footer>
  </div>
</template>

<script>
import EsHeader from '@/components/Header.vue'
import EsFooter from '@/components/Footer.vue'
import EsGoods from '@/components/Goods.vue'

// 辅助函数
import { mapActions, mapState, mapMutations } from 'vuex'
export default {
  name: 'App',
  created() {
    this.initCartList()
  },
  computed: {
    ...mapState('cart', ['cartlist'])
  },
  methods: {
    // 映射需要的Action方法
    ...mapActions('cart', ['initCartList']),
    ...mapMutations('cart',['updateGoodsState','updateGoodsCount']),
    // 商品的选中状态发生了变化
    getState(e) {
      // {id: 1, value: false}
      // console.log(e)
      this.updateGoodsState(e)
    },
    // 商品的数量发生了变化
    getCount(e) {
      // {id: 1, value: 2}
      // console.log(e)
      this.updateGoodsCount(e)
    }
  },
  components: {
    EsHeader,
    EsFooter,
    EsGoods
  }
}
</script>

<style lang="less" scoped>
.app-container {
  padding: 46px 0 50px 0;
}
</style>
